package com.wushi.lenovo.asia5b.app_event

import com.wushi.lenovo.asia5b.app_model.other.UserInfo
import com.wushi.lenovo.asia5b.app_model.wish.GoodsDetailModel
import org.greenrobot.eventbus.EventBus

/**
 * Created by zhangyuncai on 2019/12/13.
 * facebook记录日志
 */
class FacebookEvent(var javascript: String) {

    companion object {
        fun addCart(goodsModel: GoodsDetailModel, map: Map<String, Any>) {
//            val javascript = "fbq('track', 'AddToCart' , { 'currency' :prod_currency , 'qty': qty ,'value' : prod_price  , 'source' :source ,  'member_name' : gname , 'username' : gusername });"
            val javascript = """fbq('track', 'AddToCart' , { 'currency' :MYR , 'qty': ${map.get("quantity")} ,'value' : ${goodsModel.price_seller}  , 'source' :${goodsModel.source} ,  'member_name' : ${UserInfo.getUserInfo().name} , 'username' : ${UserInfo.getUserInfo().name} });"""
            EventBus.getDefault().post(FacebookEvent(javascript))
        }

        fun register() {

            val javascript = "fbq('track', 'CompleteRegistration');"
            EventBus.getDefault().post(FacebookEvent(javascript))
        }

        fun login() {
//            val javascript = "fbq('track', 'LoginSuccessful' , {'user': login_user });"
            val javascript = "fbq('track', 'LoginSuccessful' , {'user': ${UserInfo.getMemberId()} });"
            EventBus.getDefault().post(FacebookEvent(javascript))
        }

        fun ordetPayment(total: String) {
//            val javascript = "fbq('track', 'Purchase', { 'currency' : cart_currency , 'value': payment_total ,  'member_name' : gname , 'username' : gusername });"
            val javascript = "fbq('track', 'Purchase', { 'currency' : MTR , 'value': ${total} ,  'member_name' : ${UserInfo.getUserInfo().name} , 'username' : ${UserInfo.getUserInfo().name} });"
            EventBus.getDefault().post(FacebookEvent(javascript))
        }
    }
}
